// index.js
Page({
  data:{
    success:'',
  },
  onLoad:function(e){
    var that = this;//=====注意此处 要用that 指代this===== 
    wx.getStorage({
      key: 'success',
      success: function(res) {
        that.setData({
          success: res.data
        })
      },
    })
    console.log(that.data.success);
  },
  jubaotijiao:function(data){
    console.log(data.detail.value)//  {username: "hgj", password: "fsdfsd"}
  
    if (data.detail.value.xingming == '') {
      wx.showToast({
        title:'请输入姓名',
        icon:'error',
        duration:2000
    })
    }
    if (data.detail.value.zhiwu == '') {
      wx.showToast({
        title:'请输入职务',
        icon:'error',
        duration:2000
    })
    }
    if (data.detail.value.danwei == '') {
      wx.showToast({
        title:'请输入单位',
        icon:'error',
        duration:2000
    })
    }
    if (data.detail.value.keshi== '') {
      wx.showToast({
        title:'请输入科室',
        icon:'error',
        duration:2000
    })
    }
    if (data.detail.value.leibie == '') {
      wx.showToast({
        title:'请输入类别',
        icon:'error',
        duration:2000
    })
    }
    if (data.detail.value.miaoshu == '') {
      wx.showToast({
        title:'请输入描述',
        icon:'error',
        duration:2000
    })
    }
    wx.request({
      url: 'http://mini/admin/index.php/home/Api/tijiao',
      method:'get',
      //服务器的地址，现在微信小程序只支持https请求，所以调试的时候请勾选不校监安全域名
      data: {
        jubaoren:data.detail.value.jubaoren,
        dianhua:data.detail.value.dianhua,
        xingming:data.detail.value.xingming,
        zhiwu:data.detail.value.zhiwu,
        danwei:data.detail.value.danwei,
        keshi:data.detail.value.keshi,
        leibie:data.detail.value.leibie,
        miaoshu:data.detail.value.miaoshu
      },
      success: function(res) {
        console.log(res);
        if(res.data.status =='200'){
          wx.showToast({
            title:'提交成功',
            icon:'success',
            duration:2000
        })
        }else{
          wx.showToast({
            title:'提交失败',
            icon:'error',
            duration:2000
        })
        }
      }
  })
  },
  onShow: function(){//onshow函数每次加载页面时调用
     var that = this;//=====注意此处 要用that 指代this===== 
},
  radioChang: function (e) {
    console.log('radio发生change事件，携带value值为', e.detail.value)
    },
    data: {
       imgList: []
     },
     // 点击添加选择
     chooseSource: function() {
       var _this = this;
       wx.showActionSheet({
         itemList: ["拍照", "从相册中选择"],
         itemColor: "#CED63A",
         success: function(res) {
           if(!res.cancel) {
             if(res.tapIndex == 0) {
               _this.imgWShow("camera")        //拍照
             } else if (res.tapIndex == 1) {
               _this.imgWShow("album")      //相册
             }
           }
         }
       })
     },
     // 点击调用手机相册/拍照
     imgWShow: function(type) {
       var _this = this;
       let len = 0;
       if(_this.data.imgList != null) {
         len = _this.data.imgList.length
       }   //获取当前已有的图片
       wx.chooseImage({
         count: 6-len,     //最多还能上传的图片数,这里最多可以上传5张
         sizeType: ['original', 'compressed'],        //可以指定是原图还是压缩图,默认二者都有
         sourceType: [type],             //可以指定来源是相册还是相机, 默认二者都有
         success: function(res) {
           wx.showToast({
             title: '正在上传...',
             icon: "loading",
             mask: true,
             duration: 1000
           })
           // 返回选定照片的本地文件路径列表,tempFilePaths可以作为img标签的scr属性显示图片
           var imgList = res.tempFilePaths
           let tempFilePathsImg = _this.data.imgList
           // 获取当前已上传的图片的数组
           var tempFilePathsImgs = tempFilePathsImg.concat(imgList)
           _this.setData({
             imgList: tempFilePathsImgs
           })
         },
         fail: function () {
           wx.showToast({
             title: '图片上传失败',
             icon: 'none'
           })
           return;
         }
       })
       
     },
     // 预览图片
     previewImg: function(e) {
       let index = e.target.dataset.index;
       let _this = this;
       wx.previewImage({
         current: _this.data.imgList[index],
         urls: _this.data.imgList
       })
     },
     // 点击删除
     deleteImg: function(e) {
       var _this = this;
       var imgList = _this.data.imgList;
       var index = e.currentTarget.dataset.index;      //获取当前点击图片下标
       wx.showModal({
         title: '提示',
         content: '确认要删除该图片吗?',
         success: function(res) {
           if(res.confirm) {
             console.log("点击确定了")
             imgList.splice(index, 1);
           } else if (res.cancel) {
             console.log("点击取消了");
             return false
           }
           _this.setData({
             imgList
           })
         }
       })
     },

    //  鼠标点击后占位符消失
    
})
